/*
 * Copyright (c) 2013-2013 XXXX XXXXXX, Inc.
 * XXXX Road, XXXX, XXXX State, XXXX Post code, XXXX Country.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of XXXX
 * XXXXXX, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with XXXX.
 * 
 * History
 * Date        Ver Author        Change Description
 * ----------- --- ------------- ----------------------------------------
 * Some Date   001 Andrew        Create
 * 23 May 2013 002 Karl          Add elements under about tab
 */
package test.com.sms.selenium.sms.resourcemanagement.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class RmResourceManagementCompanyPageUtil extends SeleniumPageUtil {
	public final static By COMPANY_BUTTON_CLOSE = By.id("feDialogClose");
	public final static By COMPANY_BUTTON_SAVE = By.id("savescdata");
	
	// tab
	public final static By COMPANY_TAB_ABOUT = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='About'][@id='scabouttab']");
	public final static By COMPANY_TAB_ADDRESS = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='Addresses'][@id='scadressestab']");
	public final static By COMPANY_TAB_CONTACT_INFO = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='Contacts']");
	public final static By COMPANY_TAB_RATES = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='Rates']");
	public final static By COMPANY_TAB_TECHNICAL_SKILLS = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='Technical Skills']");
	public final static By COMPANY_TAB_GENERAL_SKILLS = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='General Skills']");
	public final static By COMPANY_TAB_HISTORY = By.xpath("//*[@id='saveFE']/div/ul/li/a[text()='History']");
	
	// elements under about tab
	public final static By COMPANY_LABEL_RESOURCE_TYPE = By.xpath("//form[@id='saveSC']//span[@id='subContractorTypeCodeSCError']/..");
	public final static By COMPANY_SELECT_RESOURCE_TYPE = By.xpath("//form[@id='saveSC']//select[@id='subContractorTypeCode']");
	public final static By COMPANY_INPUT_RESOURCE_TYPE = By.xpath("//form[@id='saveSC']//input[@id='subContractorTypeDesc']");
	public final static By COMPANY_LABEL_COMPANY_NAME = By.xpath("//form[@id='saveSC']//span[@id='scCompanyNameSCError']/..");
	public final static By COMPANY_INPUT_COMPANY_NAME = By.xpath("//form[@id='saveSC']//*[@id='scCompanyName']");
	public final static By COMPANY_LABEL_ADD_LOGO = By.xpath("//form[@id='saveSC']//input[@id='logoUpload']/preceding-sibling::label");
	public final static By COMPANY_FILE_ADD_LOGO = By.xpath("//form[@id='saveSC']//*[@id='logoUpload']");
	public final static By COMPANY_LABEL_NO_OF_FES = By.xpath("//form[@id='saveSC']//input[@id='numberOfFEs']/preceding-sibling::label");
	public final static By COMPANY_INPUT_NO_OF_FES = By.xpath("//form[@id='saveSC']//*[@id='numberOfFEs']");
	public final static By COMPANY_LABEL_WEEKLY_SCHEDULE = By.xpath("//form[@id='saveSC']//span[@id='standardWeeklyScheduleRefIdSCError']/..");
	public final static By COMPANY_SELECT_WEEKLY_SCHEDULE = By.xpath("//form[@id='saveSC']//*[@id='standardWeeklyScheduleRefId']");
	public final static By COMPANY_INPUT_WEEKLY_SCHEDULE = By.xpath("//form[@id='saveSC']//*[@id='standardWeeklyScheduleDescrption']");
	public final static By COMPANY_LABEL_HOLIDY_SCHEDULE = By.xpath("//form[@id='saveSC']//span[@id='holidayScheduleCodeSubContrSCError']/..");
	public final static By COMPANY_SELECT_HOLIDY_SCHEDULE = By.xpath("//form[@id='saveSC']//*[@id='holidayScheduleCodeSubContr']");
	public final static By COMPANY_INPUT_HOLIDY_SCHEDULE = By.xpath("//form[@id='saveSC']//*[@id='holidayScheduleDescSubContr']");
	public final static By COMPANY_LABEL_RESOURCE_STATUS = By.xpath("//form[@id='saveSC']//span[@id='resourceStatusRefCodeSubContrSCError']/..");
	public final static By COMPANY_SELECT_RESOURCE_STATUS = By.xpath("//form[@id='saveSC']//*[@id='resourceStatusRefCodeSubContr']");
	public final static By COMPANY_INPUT_RESOURCE_STATUS = By.xpath("//form[@id='saveSC']//input[@id='resourceStatusRefDescSubContr']");
	public final static By COMPANY_LABEL_STATUS_NOTES = By.xpath("//form[@id='saveSC']//input[@id='resourceStatusDescription']/preceding-sibling::label");
	public final static By COMPANY_INPUT_STATUS_NOTES = By.xpath("//form[@id='saveSC']//*[@id='resourceStatusDescription']");
	public final static By COMPANY_CHECK_HAS_SINGLE_POINT_LOGIN_ACCESS = By.xpath("//form[@id='saveSC']//*[@id='spLoginAccessInd']");
	public final static By COMPANY_LABEL_HAS_SINGLE_POINT_LOGIN_ACCESS = By.xpath("//form[@id='saveSC']//input[@id='spLoginAccessInd']/following-sibling::strong[1]");
	public final static By COMPANY_CHECK_HAS_SERVICE_CENTER_LOGIN_ACCESS = By.xpath("//form[@id='saveSC']//*[@id='scLoginAccessInd']");
	public final static By COMPANY_LABEL_HAS_SERVICE_CENTER_LOGIN_ACCESS = By.xpath("//form[@id='saveSC']//input[@id='scLoginAccessInd']/following-sibling::strong[1]");
	public final static By COMPANY_DIV_COMPANY_INFO = By.id("scsid");
	
	// elements under Address tab
	public final static By COMPANY_BUTTON_ADD_ADDRESS = By.xpath("//*[@id='saveFE']/div/div[text()='Add Address'][contains(@style,'display: block')]");
	// pencil and trash icons
	public final static By COMPANY_IMG_PENCILS_ADDRESS = By.xpath("//*[@id='scadresses']/div[2]/div/div[4]/table/tbody/tr/td[1]/div/img");
	public final static By COMPANY_IMG_TRASHES_ADDRESS = By.xpath("//*[@id='scadresses']/div[2]/div/div[4]/table/tbody/tr/td[2]/div/img");
	public final static By COMPANY_BUTTON_CLOSE_ADDRESS = By.id("scAddressDialogClose");
	
	// elements under contact tab
	public final static By COMPANY_BUTTON_ADD_CONTACT = By.xpath("//*[@id='saveFE']/div/div[text()='Add Contact'][contains(@style,'display: block')]");
	public final static By COMPANY_IMG_PENCILS_CONTACT = By.xpath("//*[@id='sccontacts']/div[2]/div/div[4]/table/tbody/tr/td[1]/div/img");
	public final static By COMPANY_IMG_TRASHES_CONTACT = By.xpath("//*[@id='sccontacts']/div[2]/div/div[4]/table/tbody/tr/td[2]/div/img");
	public final static By COMPANY_BUTTON_CLOSE_CONTACT = By.id("scContactDialogClose");
	
	// elements under Rates tab
	public final static By COMPANY_BUTTON_ADD_NEW_RATE = By.xpath("//*[@id='saveFE']/div/div[text()='Add New Rate'][contains(@style,'display: block')]");
	public final static By COMPANY_BUTTON_SAVE_RATES = By.id("savescdata");
	public final static By COMPANY_IMG_EDIT_LAST_RECORD = By.xpath("//*[@id='resourcerates']/div[2]/div/div[4]/table/tbody/tr[last()]/td[1]/div/img");
	public final static By COMPANY_IMG_DELETE_LAST_RECORD = By.xpath("//*[@id='resourcerates']/div[2]/div/div[4]/table/tbody/tr[last()]/td[2]/div/img");
	public final static By COMPANY_DIV_REVIEW_DATE_LAST_RECORD = By.xpath("//*[@id='resourcerates']/div[2]/div/div[4]/table/tbody/tr[last()]/td[11]/div");
	public final static By COMPANY_DIV_REVIEW_BY_LAST_RECORD = By.xpath("//*[@id='resourcerates']/div[2]/div/div[4]/table/tbody/tr[last()]/td[12]/div");
	// elements of edit rates
	public final static By COMPANY_BUTTON_CONTINUE_RATE = By.xpath("//*[@id='resourceBillingRate']/div[1]/div[2]");
	public final static By COMPANY_INPUT_BILLING_RATE_REVIEW = By.id("reviewedInd");
	public final static By COMPANY_IMG_RATE_DIALOG_CLOSE = By.id("rateDialogClose");
	public final static By COMPANY_IMG_PENCILS_RATE = By.xpath("//*[@id='resourcerates']/div[2]/div/div[4]/table/tbody/tr/td[1]/div/img");
	public final static By COMPANY_IMG_TRASHES_RATE = By.xpath("//*[@id='resourcerates']/div[2]/div/div[4]/table/tbody/tr/td[2]/div/img");
	public final static By COMPANY_BUTTON_CLOSE_RATE = By.id("rateDialogClose");
	
	// elements under Technical skills tab
	public final static By COMPANY_LABEL_SKILL_TYPE = By.xpath("//*[@id='techSkillsGroup']/table/tbody/tr[2]/td[1]/strong");
	public final static By COMPANY_SELECT_SKILL_TYPE = By.id("feAssetType");
	public final static By COMPANY_LABEL_MANUFACTURER = By.xpath("//*[@id='techSkillsGroup']/table/tbody/tr[2]/td[2]/strong");
	public final static By COMPANY_SELECT_MANUFACTURER = By.id("manufacturerId");
	public final static By COMPANY_LABEL_PROD_FAMILY = By.xpath("//*[@id='techSkillsGroup']/table/tbody/tr[2]/td[3]/strong");
	public final static By COMPANY_SELECT_PROD_FAMILY = By.id("feAssetSubType");
	public final static By COMPANY_LABEL_PROFICIENCY = By.xpath("//*[@id='techSkillsGroup']/table/tbody/tr[2]/td[4]/strong");
	public final static By COMPANY_SELECT_PROFICIENCY = By.id("proficiencyTypeId");
	public final static By COMPANY_LABEL_DISPATCH_PREF = By.xpath("//*[@id='techSkillsGroup']/table/tbody/tr[2]/td[5]/strong");
	public final static By COMPANY_SELECT_DISPATCH_PREF = By.id("skillDispatchingType");
	public final static By COMPANY_BUTTON_ADD_SKILL_SETS = By.id("create-techskillset-btn-sc");
	public final static By COMPANY_SELECT_SKILL_TYPE_EDIT = By.id("feAssetTypeOverlay");
	public final static By COMPANY_SELECT_MANUFACTURER_EDIT = By.id("manufacturerIdOverlay");
	public final static By COMPANY_SELECT_PROD_FAMILY_EDIT = By.id("feAssetSubTypeOverlay");
	public final static By COMPANY_BUTTON_CONTINUE_SKILL_SET = By.xpath("//*[@id='techSkillGroupOverlay']/div/div[text()='Continue']");
	// records of skill sets
	public final static By COMPANY_TR_RECORDS_TECHNICAL_SKILL = By.xpath("//*[@id='resourcetechnicalskills']/div[3]/div/div[4]/table/tbody/tr");
	
	
	// elements under generial skills tab
	public final static By COMPANY_BUTTON_ADD_NEW_CERTIFICATE = By.xpath("//*[@id='saveFE']/div/div[text()='Add New Certificate'][contains(@style,'display: block')]");
	public final static By COMPANY_STRONG_SKILL_TYPE = By.xpath("//*[@id='feGenSkillsGroup']/table/tbody/tr[2]/td[1]/strong");
	public final static By COMPANY_SELECT_SKILL_TYPE_SKILL_SETS = By.id("abstractSkillTypeCode");
	public final static By COMPANY_SELECT_SKILL_TYPE_SKILL_SETS_EDIT = By.id("abstractSkillTypeCodeOverlay");
	public final static By COMPANY_STRONG_SKILL_NAME = By.xpath("//*[@id='feGenSkillsGroup']/table/tbody/tr[2]/td[2]/strong");
	public final static By COMPANY_SELECT_SKILL_NAME_GENERAL_SKILL = By.id("abstractGenSkillId");
	public final static By COMPANY_SELECT_SKILL_NAME_EDIT = By.id("abstractGenSkillIdOverlay");
	public final static By COMPANY_BUTTON_CONTINUE_GENERIAL_SKILL_SET = By.xpath("//*[@id='feGeneralSkillsGroupOverlay']/div[1]/div[text()='Continue']");
	public final static By COMPANY_BUTTON_ADD_SKILL_SET_GENERAL_SKILL = By.id("create-genskillset-btn-sc");
	
	// elements under history tab
	public final static By COMPANY_DIV_CLIENT_NAME = By.xpath("//*[@id='resourcehistories']/div[2]/div/div[3]/div/table/thead/tr/th[1]/div");
	public final static By COMPANY_DIV_TICKET_NUMBER = By.xpath("//*[@id='resourcehistories']/div[2]/div/div[3]/div/table/thead/tr/th[2]/div");
	public final static By COMPANY_DIV_OPEN_DATE = By.xpath("//*[@id='resourcehistories']/div[2]/div/div[3]/div/table/thead/tr/th[3]/div");
	public final static By COMPANY_DIV_CLOSE_DATE = By.xpath("//*[@id='resourcehistories']/div[2]/div/div[3]/div/table/thead/tr/th[4]/div");
	public final static By COMPANY_DIV_STATUS = By.xpath("//*[@id='resourcehistories']/div[2]/div/div[3]/div/table/thead/tr/th[5]/div");
	public final static By COMPANY_INPUT_STATUS_NOTE = By.id("resourceStatusDescription");
	public final static By COMPANY_DIV_STATUS_INFO = By.id("scsid");
	// on history tab the edit and delete icon should not be found
	public final static By COMPANY_IMG_EDIT_ICON = By.xpath("//*[@id='resourcehistories']//img[@src='/images/edit.png']");
	public final static By COMPANY_IMG_DELETE_ICON = By.xpath("//*[@id='resourcehistories']//img[@src='/images/edit.png']");
	
	// element of last record in ticket list
	public final static By COMPANY_TD_LAST_COMPANY = By.xpath("//*[@id='table-data']/tbody/tr[last()]/td[1]");
	public final static By COMPANY_TBODY_RESULTS = By.xpath("//*[@id='table-data']/tbody");
	
	public final static void waitForCompanyPageLoad(){
//		SeleniumUtil.waitOnElements(new By[]{
//				COMPANY_BUTTON_CLOSE, COMPANY_BUTTON_SAVE, COMPANY_TAB_ABOUT, COMPANY_TAB_ADDRESS, 
//				COMPANY_TAB_CONTACT_INFO, COMPANY_TAB_RATES, COMPANY_TAB_TECHNICAL_SKILLS, 
//				COMPANY_TAB_GENERAL_SKILLS, COMPANY_TAB_HISTORY
//		});
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_BUTTON_CLOSE)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_BUTTON_SAVE)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_ABOUT)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_ADDRESS)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_CONTACT_INFO)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_RATES)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_TECHNICAL_SKILLS)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_GENERAL_SKILLS)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(COMPANY_TAB_HISTORY)));
	}
	
	/**
	 * edit the status note of company, save and close it.
	 * open the same company and get the text of status note and return it.
	 */
	public final static String editCompanyNote(String companyName, String text){
		final By COMPANY_TD_EDIT_COMPANY_FLAG = By.xpath("//*[@id='table-data']/tbody/tr/td[text()='" + 
				companyName + "']/preceding-sibling::td[1]");
		// change the status note and save it.
		SeleniumUtil.waitOnElements(new By[]{COMPANY_TD_EDIT_COMPANY_FLAG});
		SeleniumUtil.click(SeleniumUtil.findElement(COMPANY_TD_EDIT_COMPANY_FLAG));
		SeleniumUtil.waitOnElements(new By[]{COMPANY_INPUT_STATUS_NOTES});
		SeleniumUtil.clear(SeleniumUtil.findElement(COMPANY_INPUT_STATUS_NOTES));
		SeleniumUtil.sendKeys(SeleniumUtil.findElement(COMPANY_INPUT_STATUS_NOTES), text);
		SeleniumUtil.waitOnElements(new By[]{COMPANY_BUTTON_SAVE});
		SeleniumUtil.click(SeleniumUtil.findElement(COMPANY_BUTTON_SAVE));
		SeleniumUtil.waitOnElements(new By[]{COMPANY_BUTTON_CLOSE});
		SeleniumUtil.click(SeleniumUtil.findElement(COMPANY_BUTTON_CLOSE));
		SeleniumUtil.waitForFixedMilliseconds(3000);
		
		// get the status note text.
		SeleniumUtil.waitOnElements(new By[]{COMPANY_TD_EDIT_COMPANY_FLAG});
		SeleniumUtil.click(SeleniumUtil.findElement(COMPANY_TD_EDIT_COMPANY_FLAG));
		SeleniumUtil.waitForFixedMilliseconds(1000);
		SeleniumUtil.waitOnElements(new By[]{COMPANY_INPUT_STATUS_NOTES});
		return SeleniumUtil.findElement(COMPANY_INPUT_STATUS_NOTES).getAttribute("value");
	}
}
